#!/bin/bash
SCRIPT_BASE_DIR=$( dirname "${BASH_SOURCE[0]}" )
source "${SCRIPT_BASE_DIR}/common/fs_utils.sh"

function usage() {
    echo "Usage: $( basename $0 ) [-h | -c] <App_Prj_Name>"
    echo "    Running an application binary manually"
    echo "    <App_Prj_Name>: App项目路径"
    echo "    -h: print this message"
    echo "    -c: 运行APP前启动container"
    exit 
}

runContainer=false
while getopts ":hc" args
do
    case "$args" in
    h)
        usage
        ;;
    c)
        runContainer=true
        ;;
    *)
        usage
        ;;
    esac
    shift
done

if [ -z "$1" ]
then
    usage
fi

AppPath="$1"
AppName=$( basename ${AppPath} )
dir_exists_or_die ${AppPath}

if [ "true" == ${runContainer} ]
then
    echo ara-cli TargetOperation --target-host  fd00::eb:2 --remote-command \"systemctl start ${AppName}\"
    ara-cli TargetOperation --target-host  fd00::eb:2 --remote-command \"systemctl start ${AppName}\"
fi
    
echo ara-cli TargetOperation --app-dir ${AppPath} --remote-command \"runc exec -t ${AppName} ${AppName}\"
ara-cli TargetOperation --app-dir ${AppPath} --remote-command \"runc exec -t ${AppName} ${AppName}\"
